import java.util.*;

class Solution {
    public int[] findOrder(int numCourses, int[][] prerequisites) {
        int[] in=new int[numCourses];
        HashMap<Integer,List<Integer>> hash=new HashMap<>();
        for(int i=0;i<prerequisites.length;i++){
            int a=prerequisites[i][0];
            int b=prerequisites[i][1];
            List<Integer> list=hash.getOrDefault(b,new ArrayList<Integer>());
            list.add(a);
            hash.put(b,list);
            in[a]++;
        }


        return bfs(hash,in);


    }

    private int[] bfs(HashMap<Integer, List<Integer>> hash, int[] in){
        int i=0,count=0;
        int[] ret=new int[in.length];
        Queue<Integer> q=new LinkedList<>();
        for(i=0;i<in.length;i++){
            if(in[i]==0) q.add(i);
        }



        while(!q.isEmpty()){
            int cur=q.poll();
            ret[count]=cur;
            List<Integer> list=hash.get(cur);
            count++;
            if(count==in.length) return ret;



            if(list!=null)
                for(int j:list){
                    if(--in[j]==0) q.add(j);
                }



        }
        return new int[0];

    }

    public static void main(String[] args) {
        ArrayList<Integer> arrayList=new ArrayList<>();
        arrayList.add(1);
        System.out.println(arrayList.contains(1));
    }
}